<template>
  <div>
    <table-where :forms="forms"></table-where>
    <wms-table ref="tableQuery" :tableDatas="tableDatas" @confirmHandle="confirmHandle" @detailClick="detailClick"></wms-table>
  </div>
  <el-dialog v-model="setPicking" title="分拣数量" draggable width="20%">
    <table-where :forms="editForms"></table-where>
  </el-dialog>
</template>

<script setup name="待分拣">
import { ref, reactive } from 'vue'
import { POSTJSON } from '@/components/utils/http'
import { MessageBox } from '@/components/utils/api'
import { useWmsGlobal } from '@/store/wmsGlobal'
const wmsGlobal = useWmsGlobal()
const setPicking = ref(false);
const tableDatas = reactive({
  body: {
    //表数据
    head: 'picking',
    url: '/InStore/getArrivedPage',
    params: { in_store_stat: 4 },
    type: 'POSTJSON'
  },
  confirm: true
})

const tableQuery = ref()
const onSubmit = () => {
  tableQuery.value.getData()
}
const editForms = reactive({
  data: {picking_qty:0,id:null},
  compValue: [
    { label: '拣货数量', value: 'picking_qty',type: 'numberInput', show: true},
    {
      label: '确认',
      type: 'button',
      onclick: () => {
        POSTJSON('/InStore/updateNoticeDetail', editForms.data).then(data => {
          if (data.code ===200){
            onSubmit();
            setPicking.value = false;
          }
        })
      }
    },
  ]
})
const forms = reactive({
  data: tableDatas.body.params,
  compValue: [
    {
      placeholder: '供应商',
      value: 'params',
      id: 'c_id',
      type: 'iconinput',
      onclick: () => {
        wmsGlobal.getClient(forms.data.params).then(data => {
          forms.data.c_id = data.id
          forms.data.params = data.name
        })
      }
    },
    {
      placeholder: '商品信息',
      value: 'paramsG',
      id: 'g_id',
      type: 'iconinput',
      onclick: () => {
        wmsGlobal.getGoods(forms.data.paramsG).then(data => {
          forms.data.g_id = data.id
          forms.data.paramsG = data.name
        })
      }
    },
    { label: '查询', type: 'button', onclick: onSubmit }
  ]
})
const detailClick = (row)=>{
  setPicking.value = true;
  editForms.data.picking_qty = row.picking_qty;
  editForms.data.id = row.id;
}
const confirmHandle = ({ row }) => {
  MessageBox('【' + row.name + '】分拣完成吗', () => {
    POSTJSON('/InStore/updateNoticeDetail', { in_store_stat: 5, id: row.id }).then(data => {
      if (data.code === 200) {
        onSubmit()
      }
    })
  })
}
</script>
